package com.mf.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.bo.IDs;
import com.mf.bo.TransactionsBatchBo;
import com.mf.entity.Code;
import com.mf.entity.CodeHistory;
import com.mf.entity.Positions;
import com.mf.entity.Transactions;
import com.mf.enums.DealTypeEnum;
import com.mf.enums.TransactionStatusEnum;
import com.mf.exceptions.GraceException;
import com.mf.mapper.PositionsMapper;
import com.mf.result.Result;
import com.mf.service.ICodeHistoryService;
import com.mf.service.ICodeService;
import com.mf.service.IPositionsService;
import com.mf.service.ITransactionsService;
import com.mf.utils.EnumUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;


/**
* <p>
    * 交易表 前端控制器
    * </p>
*
* @author mf
* @since 2024-06-08
*/
@RestController
@RequestMapping("/transactions")
public class TransactionsController {
    @Resource
    private ITransactionsService transactionsService;
    @Resource
    private ICodeHistoryService codeHistoryService;

    /**
     * 新增交易记录
     */
    @PostMapping("/add")
    @Transactional
    public Result<Integer> add(@Valid @RequestBody Transactions transactions)
    {
        return Result.success(transactionsService.add(transactions));
    }

    /**
     * 批量新增交易记录
     */
    @PostMapping("/addBatch")
    public Result<String> addBatch(@RequestBody TransactionsBatchBo transactionsBatchBo)
    {
        final List<CodeHistory> listHistory = codeHistoryService.getByCodeListHistory(transactionsBatchBo.getDms());
        transactionsService.addBatch(transactionsBatchBo,listHistory);
        return Result.success();
    }

}
